﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml.Linq;
using data.contracts.messages;
using ebc.viz.frontend;
using ebc.viz.modelbuilder;
using ebc.viz.modelrenderer;
using ebcpatterns.flow;
using modelbuilder;
using modelbuilder.parts;

namespace ebc.viz.app
{
    static class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var frontend = new WinViewer();

            var board = new contracts.MainBoard(
                new Validate_commandline_params(),
                new Collect_board_definitions_from_project(),
                new Map<string[],BuildBoardsMessage>(filenames => new BuildBoardsMessage(filenames, "")),
                new ModelBuilder(
                    new XmlFileAdapter(),
                    new Join<IEnumerable<XDocument>, string>(),
                    new BoardBuilder(),
                    new ExpandSplitWires(),
                    new ExpandJoinWires(),
                    new Parse_Pins()
                    ),
                new Render_boards(),
                frontend
                );

            try
            {
                board.Run(args);
                Application.Run(frontend);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ebc.xml Visualizer", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
